package com.ityy.ruiji.controller;

import com.ityy.ruiji.common.R;
import com.ityy.ruiji.entity.dto.SetmealDto;
import com.ityy.ruiji.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @PostMapping
    public R save(@RequestBody SetmealDto setmealDto , HttpSession httpSession){
        Long employee = (Long) httpSession.getAttribute("employee");
        setmealDto.setCreateUser(employee);
        setmealDto.setUpdateUser(employee);
        R result = setmealService.save(setmealDto);
        return result;
    }

    @GetMapping("/page")
    public R page (@RequestParam(defaultValue = "1")Integer page,
                   @RequestParam(defaultValue = "10")Integer pageSize,String name){
        R result = setmealService.page(page,pageSize,name);
        return result;
    }

    @DeleteMapping
    private R deleteByIds(@RequestParam List<Long> ids){
       R result = setmealService.deleteByIds(ids);
       return result;
    }

    @GetMapping("list")
    public R list(Long categoryId,Integer status){
       R relust = setmealService.findById(categoryId,status);
       return relust;
    }
}
